//
//  TestSerialization.cpp
//  Nano
//
//  Created by Jeppe Nielsen on 9/1/13.
//  Copyright (c) 2013 Jeppe Nielsen. All rights reserved.
//

#include <iostream>
#include "tinyxml.h"
#include "FileReader.hpp"
#include "Vector2.hpp"
#include "GameWorld.hpp"
#include "Sizeable.hpp"
#include "Transform.hpp"
#include "Colorable.hpp"
#include "Orderable.hpp"

using namespace Nano;

void build_simple_doc( )
{
    
    std::string path = Nano::FileReader::GetWritablePath();

	// Make xml: <?xml ..><Hello>World</Hello>
	TiXmlDocument doc;
	TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "", "" );
	TiXmlElement * element = new TiXmlElement( "Hello" );
	TiXmlText * text = new TiXmlText( "World" );
	element->LinkEndChild( text );
	doc.LinkEndChild( decl );
	doc.LinkEndChild( element );
	doc.SaveFile( (path + "/madeByHand.xml").c_str() );
}

void testSimple() {
    
    std::string path = Nano::FileReader::GetWritablePath() + "/test.xml";
    
    TiXmlDocument xmlFile;
    
    TiXmlElement* element = new TiXmlElement("Transform");
    
    element->SetAttribute("Position", "1.0f,3.0f,32.0f");
    
    
    xmlFile.LinkEndChild(element);
    
    xmlFile.SaveFile(path.c_str());
}



class SizeSystem : public GameSystem {
public:
    void Initialize() {
        AddComponent<Sizeable>();
        AddComponent<Transform>();
        AddComponent<Colorable>();
        AddComponent<Orderable>();
    }
    
};


void testComponentSerialization() {
    
    std::string path = Nano::FileReader::GetWritablePath() + "/test.xml";
    
    GameWorld world;
    world.CreateSystem<SizeSystem>();
    
    GameObject* gadget = world.CreateObject();
    gadget->AddComponent<Sizeable>();
    gadget->AddComponent<Transform>()->Position = Vector3(23.4f,10.0f, 50.0f);
    gadget->AddComponent<Colorable>()->Color = Colour::Red();
    gadget->AddComponent<Orderable>()->Order = 1024;
    
    gadget->Save(path);
    
    GameObject* copy = world.Load(path);
    Vector3 position = copy->GetComponent<Transform>()->Position;
    
    world.Debug();
    
    Vector3 v(6,5);
    
    std::cout<<v;
    
    stringstream s;
    s<<v;
    
    std::string sd = s.str();
    
}

/*
int main() {
    testComponentSerialization();
    return 0;
}
*/
